package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"io/ioutil"
	"net"
	"time"
)

func main() {
	DiscardTest()
}

func DiscardTest() {
	i := ioutil.Discard
	n, e := i.Write([]byte("test"))
	fmt.Println(n, e)
	b := bufio.NewWriter(i)
	r := bytes.NewBuffer(make([]byte, 0, 1204))
	r.WriteString("....!")
	n1, e := r.WriteTo(b)
	fmt.Println(n1, e)
}

func tcpTest() {
	l, err := net.Listen("tcp", ":8888")
	if err != nil {
		fmt.Println(err)
		return
	}
	for {
		c, err := l.Accept()
		if err != nil {
			fmt.Println(err)
			return
		}
		go handleClientRequest(c)
	}
}

func handleClientRequest(c net.Conn) {
	start := time.Now()
	byteCon := make([]byte, 1024)
	r := bytes.NewBuffer(make([]byte, 0, 65535))
	io.Copy(r, c)
	n, err := r.Read(byteCon)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(string(byteCon[:n]))
	fmt.Println(time.Since(start))
}
